from pyramid.view import view_config
from pyramid.httpexceptions import HTTPFound


@view_config(route_name='home', renderer='templates/mytemplate.pt')
def my_view(request):
	if request.sessions.get('view_ad', 'no') != 'yes':
		raise HTTPFound(request.route_url('ad'))
	return {'project': 'SessionTest'}


@view_config(route_name='ad', renderer='templates/ad.pt')
def test_view(request):
	if request.sessions.get('view_ad', 'no') == 'yes':
		del request.sessions['']
		return HTTPFound(request.route_url('home'), headers=response.headers)
	return {'project': 'TestView'}


@view_config(route_name='confirm_ad')
def confirmad_view(request):
	response = request.response
	response.set_cookie('view_ad', value='yes')
	return HTTPFound(request.route_url('home'), headers=response.headers)
